package com.yiwei.jmx.adapter;

import android.content.Context;
import android.graphics.Typeface;
import android.support.v7.widget.RecyclerView;
import android.text.Spanned;
import android.view.View;
import android.view.ViewGroup;

import com.allen.library.SuperButton;
import com.yiwei.jmx.R;
import com.yiwei.jmx.api.model.DealIndexDetailModel;
import com.yiwei.jmx.util.Spans;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class YmdBorrowMenuAdapter extends ItemAdapter<DealIndexDetailModel.DataBean.ItemBean, YmdBorrowMenuAdapter.DefaultHolder> {


    private final int x24;
    private final int x30;
    private Context context;

    public YmdBorrowMenuAdapter(Context context) {
        super(context);
        this.context = context;
        x24 = context.getResources().getDimensionPixelSize(R.dimen.x24);
        x30 = context.getResources().getDimensionPixelSize(R.dimen.x30);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_ymd_menu, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        DealIndexDetailModel.DataBean.ItemBean item = getItem(position);
        Spanned txt_content = Spans.with(context).font(item.title, x30, 0xffFFFFFF).style(Typeface.BOLD).
                font("\n" + item.desc, x24, 0xffFFFFFF).
                build();
        holder.txtMenu.setText(txt_content);
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_menu)
        SuperButton txtMenu;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onSuccess();
    }
}
